package org.jeecg.modules.qyxx.service.impl;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.qyxx.entity.BgFpHzNdSygys;
import org.jeecg.modules.qyxx.entity.BgFpHzNdWdxSxygysjxs;
import org.jeecg.modules.qyxx.entity.BgFpHzNdXyjxs;
import org.jeecg.modules.qyxx.enumdemo.RedisKeyConstant;
import org.jeecg.modules.qyxx.mapper.BgFpHzNdWdxSxygysjxsMapper;
import org.jeecg.modules.qyxx.service.IBgFpHzNdWdxSxygysjxsService;
import org.jeecg.modules.qyxx.service.IBgSjmkjgOrderService;
import org.jeecg.modules.qyxx.util.DateUtils;
import org.jeecg.modules.qyxx.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Description: 上下游供应商和经销商稳定性汇总数据
 * @Author: ZJJ
 * @Date: 2021-06-10
 * @Version: V1.0
 */
// @DS("multi-datasource1")申报
@Service
public class BgFpHzNdWdxSxygysjxsServiceImpl extends MppServiceImpl<BgFpHzNdWdxSxygysjxsMapper, BgFpHzNdWdxSxygysjxs> implements IBgFpHzNdWdxSxygysjxsService {

    @Override
    public List<BgFpHzNdWdxSxygysjxs> fpHzNdWdxSxygysjxs(String djxh, List<String> tjnds, Date jssj) {
        DateUtils utils = DateUtils.getInstance();
        LambdaQueryWrapper<BgFpHzNdWdxSxygysjxs> wrapper = Wrappers.lambdaQuery(BgFpHzNdWdxSxygysjxs.class);
        // String year = bgSjmkjgOrderService.getNewByDjxh(djxh);
        String year = utils.getYearToStr(jssj);
        // List<BgFpHzNdWdxSxygysjxs> list = new ArrayList<>();
        List<BgFpHzNdWdxSxygysjxs> list = baseMapper.fpHzNdWdxSxygysjxs(djxh, String.join(",", tjnds));
        for (BgFpHzNdWdxSxygysjxs bgFpHzNdWdxSxygysjxs : list) {
            if (year.equals(bgFpHzNdWdxSxygysjxs.getTjnd())){
                // String month = bgSjmkjgOrderService.getNewMonthByDjxh(djxh);
                String month = utils.getMonthToStr(jssj);
                String newMonth = month.substring(month.length()-2);
                bgFpHzNdWdxSxygysjxs.setTjnd(year + "年(" + newMonth + "月)");
            }else {
                bgFpHzNdWdxSxygysjxs.setTjnd(bgFpHzNdWdxSxygysjxs.getTjnd() + "年");
            }
        }
        return list;
       /* int i = 0;
        for (String tjnd : tjnds) {
            wrapper.clear();
            wrapper.eq(BgFpHzNdWdxSxygysjxs::getDjxh, djxh).eq(BgFpHzNdWdxSxygysjxs::getTjnd, tjnd);
            BgFpHzNdWdxSxygysjxs one = bgFpHzNdWdxSxygysjxsMapper.selectOne(wrapper);
            if (one != null) {
                if (year.equals(one.getTjnd())){
                    // String month = bgSjmkjgOrderService.getNewMonthByDjxh(djxh);
                    String month = utils.getMonthToStr(jssj);
                    String newMonth = month.substring(month.length()-2);
                    one.setTjnd(year + "年(" + newMonth + "月)");
                }else {
                    one.setTjnd(one.getTjnd() + "年");
                }
                list.add(one);
                i++;
                if (i >= 3) {
                    break;
                }
            }
        }*/
    }
}
